mui.init({

});

mui(".mui-table-view").on("tap", "a", function() {
	var targetPageId = plus.webview.currentWebview().id;
	plus.storage.setItem(KeyCfg.targetPageId,targetPageId);
	var self = this;
	var contextId=$(self).attr("articleId");
	var title = $(self).attr("title");
	var id = $(self).attr("deputysectionId");
	/*-------  官方公告 CODE START -------*/
	var notice_url = UrlConfig.official_notice_context;
	var news_url = UrlConfig.company_news_context;
	var media_url = UrlConfig.media_report_context;
		switch(id){
		case '7':
			$.ajax(notice_url, {  
        data : {id:id,contextId:contextId},  
        dataType : 'text',  
        crossDomain: true,  
        success: function(data) {
		var cfg = {pars :{title:title,data:data,columnid:id}};
		MuiEventMgr.open('../officialtrend/showpage.html',cfg);
        }
    });
			break;
			case '9':
			$.ajax(news_url, {  
		        data : {id:id,contextId:contextId},  
		        dataType : 'text',  
		        crossDomain: true,  
		        success: function(data) {
		        var cfg = {pars :{title:title,data:data,columnid:id}};
				MuiEventMgr.open('../officialtrend/showpage.html',cfg);
        }
    });
			break;
			case '51':
			$.ajax(media_url, {  
       data : {id:id,contextId:contextId},  
        dataType : 'text',  
        crossDomain: true,  
        success: function(data) {
        	var cfg = {pars :{title:title,data:data,columnid:id}};
			MuiEventMgr.open('../officialtrend/showpage.html',cfg);
        }
    });
			break;
	}
});


mui.plusReady(function() {
	function activeTabItem(tabItemId){
		if(tabItemId == "defaultTab") return;/*默认选中的是第一个选项卡*/
		var tabItem = $("#"+tabItemId);
		tabItem.addClass("mui-active");
		var href = tabItem.attr("href");
	    $(href).show();
	    $("#defaultTab").removeClass("mui-active");
	    $("#itemnews1").hide();	
	}
	var activeTabItemId = plus.webview.currentWebview().activeTabItemId;
	if(!activeTabItemId) activeTabItemId = "defaultTab";
	//activeTabItem(activeTabItemId);
	var defaultTab = document.getElementById(activeTabItemId);
	//模拟首页点击
	mui.trigger(defaultTab,'tap');

	
	/*-------  官方公告 CODE START -------*/
	var articleId = 7;
	var doing_url = UrlConfig.official_notice;
	$.ajax(doing_url, {  
        data : {articleId:articleId},  
        dataType : 'jsonp',  
        crossDomain: true,  
        success: function(data) {
        		data = JSON.parse(data);
        		callback(data);
        }
    });
    
    function callback(data){
    		var Articles=data.Articles;
    		if(typeof(Articles) == 'undefined'){
    			$("#itemnews1").css("display","none");
		        $("#noRecord1").css("display","");
			return;
	}
    		var htmlArr = [];
    		for(var i=0,len=Articles.length; i<len; i++){
    			var Article = Articles[i];
    			htmlArr[i] = getJbHtml(Article);
    		}
    		var htmlStr = htmlArr.join(" ");
    		$("#article_show1").html(htmlStr);
    		
    }
    
    function getJbHtml(Article){
		var articleId = Article.articleId;
		var title = Article.title;
		var creatTime = Article.creatTime;
		var YMD = creatTime.substr(0,10);
		var deputysectionId = Article.deputysectionId;
		//var a = Article.context;
    		var htmlArr = [
    			'<li class="mui-table-view-cell">',
    			'<a class="mui-navigate-right"  articleId="'+articleId+'" deputysectionId="'+deputysectionId+'" title="'+title+'">',
			//'	<div class="mui-table">',
			'		<div class="mui-table-cell mui-col-xs-10">',
			'		<span>'+title+'</span>',
			'		<p class="mui-h6 mui-ellipsis">'+YMD+'</p>',
			'       </div>',
			'		<div class="mui-table-cell mui-col-xs-2 mui-text-right">',
			'	</div>',
			//'	</div>',
			'		</a>',
			'</li>'
			];
		return htmlArr.join(" ");
    }/*-------  官方公告 CODE END -------*/

   /*-------  公司新闻 CODE START -------*/
  	//var news_url = UrlConfig.company_news;
  	var newsId = 9;
  	var news_url = UrlConfig.company_news;
	$.ajax(news_url, {  
        data : {newsId:newsId},  
        dataType : 'jsonp',  
        crossDomain: true,  
        success: function(data) {
        		data = JSON.parse(data);
        		callback3(data);
        }
    });
    
    function callback3(data){
    		var Articles=data.Articles;
    		if(typeof(Articles) == 'undefined'){
    			$("#itemnews2").css("display","none");
		        $("#noRecord1").css("display","");
			return;
	}
    		var htmlArr = [];
    		for(var i=0,len=Articles.length; i<len; i++){
    			var Article = Articles[i];
    			htmlArr[i] = getJbHtml3(Article);
    		}
    		var htmlStr = htmlArr.join(" ");
    		$("#article_show2").html(htmlStr);
    }
    
    function getJbHtml3(Article){
		var articleId = Article.articleId;
		var title = Article.title.trim();
		var creatTime = Article.creatTime;
		var YMD = creatTime.substr(0,10);
		var deputysectionId = Article.deputysectionId;
    		var htmlArr = [
    			'<li class="mui-table-view-cell">',
    			'<a class="mui-navigate-right"  articleId="'+articleId+'" deputysectionId="'+deputysectionId+'" title="'+title+'">',
			'		<div class="mui-table-cell mui-col-xs-10">',
			'		<span>'+title+'</span>',
			'		<p class="mui-h6 mui-ellipsis">'+YMD+'</p>',
			'       </div>',
			'		<div class="mui-table-cell mui-col-xs-2 mui-text-right">',
			'	</div>',
			'		</a>',
			'</li>'
			];
		return htmlArr.join(" ");
    }/*-------  公司新闻 CODE END -------*/
   
   /*-------  媒体报道 CODE START -------*/
  	//var news_url = UrlConfig.media_report;
  	var mediaId = 51;
  	var media_url = UrlConfig.media_report;
	$.ajax(media_url, {  
        data : {mediaId:mediaId},  
        dataType : 'jsonp',  
        crossDomain: true,  
        success: function(data) {
        		data = JSON.parse(data);
        		callback4(data);
        }
    });
    
    function callback4(data){
    		var Articles=data.Articles;
    		if(typeof(Articles) == 'undefined'){
    			$("#itemnews3").css("display","none");
		        $("#noRecord1").css("display","");
			return;
	}
    		var htmlArr = [];
    		for(var i=0,len=Articles.length; i<len; i++){
    			var Article = Articles[i];
    			htmlArr[i] = getJbHtml3(Article);
    		}
    		var htmlStr = htmlArr.join(" ");
    		$("#article_show3").html(htmlStr);
    		//$("#itemnews2").css("display","none");
	        //$("#itemnews3").css("display","none");
    }
    
    function getJbHtml4(Article){
		var articleId = Article.articleId;
		var title = Article.title;
		var creatTime = Article.creatTime;
		var YMD = creatTime.substr(0,10);
		var deputysectionId = Article.deputysectionId;
		//var a = Article.context;

    		var htmlArr = [
    			'<li class="mui-table-view-cell">',
    			'<a class="mui-navigate-right"  articleId="'+articleId+'" deputysectionId="'+deputysectionId+'" title="'+title+'">',
			//'	<div class="mui-table">',
			'		<div class="mui-table-cell mui-col-xs-10">',
			'		<span>'+title+'</span>',
			'		<p class="mui-h6 mui-ellipsis">'+YMD+'</p>',
			'       </div>',
			'		<div class="mui-table-cell mui-col-xs-2 mui-text-right">',
			'	</div>',
			//'	</div>',
			'		</a>',
			'</li>'
			];
		return htmlArr.join(" ");
    }/*-------  媒体报道 CODE END -------*/
   
   
  
		var defaultTab = CmwMcore.$("officialtrend_2");
	    MeventMgr.onTouchstart(defaultTab,function(event,self){
			$("#defaultTab").css("background-color","#EEEEEE");
			$("#defaultTab").css("color","black");
			$("#officialtrend_2").css("background-color","white");
			$("#officialtrend_3").css("background-color","#EEEEEE");
			$("#officialtrend_2").css("color","#0b56a7");
			$("#officialtrend_3").css("color","black");

		});
		var defaultTab = CmwMcore.$("officialtrend_3");
	    MeventMgr.onTouchstart(defaultTab,function(event,self){
			$("#defaultTab").css("background-color","#EEEEEE");
			$("#defaultTab").css("color","black");
			$("#officialtrend_3").css("background-color","white");
			$("#officialtrend_2").css("background-color","#EEEEEE");
			$("#officialtrend_3").css("color","#0b56a7");
			$("#officialtrend_2").css("color","black");

		});
		var defaultTab = CmwMcore.$("defaultTab");
	    MeventMgr.onTouchstart(defaultTab,function(event,self){
			$("#defaultTab").css("background-color","white");
			$("#defaultTab").css("color","#0b56a7");
			$("#officialtrend_3").css("background-color","#EEEEEE");
			$("#officialtrend_2").css("background-color","#EEEEEE");
			$("#officialtrend_3").css("color","black");
			$("#officialtrend_2").css("color","black");

		});


});

